package com.neusoft.dibuy.kafka.producer.interceptor;

import org.apache.kafka.clients.producer.*;
import org.apache.kafka.common.serialization.StringSerializer;

import java.util.HashMap;
import java.util.Map;

public class InterceptorDemoApp {
    public static void main(String[] args) {
        /**
         * TODO :  s生产者
         */

        Map<String, Object> config = new HashMap<>();
        config.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
        config.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
        config.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
        KafkaProducer<String, String> producer = new KafkaProducer<String, String>(config);
        /**
         * TODO : 消息
         */
        ProducerRecord<String, String> record = new ProducerRecord<String, String>("test", "key", "hello kafka");
        /**
         * TODO : 发送消息
         *
         */
        producer.send(record, (metadata, exception) -> {
            
            System.out.println("消息发送成功");
        });

        /**
         * TODO : 关闭资源
         */

        producer.close();

    }
}
